/**
 * Created by tsy on 2017/5/24.
 */
Vue.http.options.emulateJSON = true;
new Vue({
    el: '#index',
    data: {
        borrow_json:[],
        suppledetail_json:[],
        url:"ajax_borrow_detail",
        remark_url:"ajax_supple_detail",
        remark_table_url:"ajax_remark_table",
        newfile_url:"../../Customer/CustReference/select_count_new_file",
        credit_url:"../../Customer/CustCredit/borrow_detail_credit",
        fm_table_url:"../../Customer/CustCredit/select_fm_table",
        zmxy_table_url:"../../Customer/CustCredit/select_zmxy_table",
        zmxy_select_url:"../../Customer/CustCredit/curl_select_zmxy",
        zmxy_delete_url:"../../Customer/CustCredit/delete_zmxy_score",
        vpn_select_url:"../../Customer/CustCredit/select_vpn",
        anrong_createapply_url:"../../Customer/CustCredit/anrong_createapply",
        second_examine_url:"borrow_second_examine",
        reject_examine_url:"borrow_reject_examine",
        cancel_borrow_url:"borrow_cancel",
        file_zip_url:"file_zip",
        select_borrow_period:"select_borrow_period",
        select_borrow_data:"select_borrow_data",
        subimit_borrow_period:"subimit_borrow_period",
        submit_borrow_data:"submit_borrow_data",
        ajax_borrow_array:{borrow_id:borrow_id},
        file_count:"",
        shzx_array:[],
        zmxy_array1:[],
        zmxy_array2:[],
        period_array:{},
        period_check:{},
        data_array:{}
    },
    created: function() {
        this.getBorrowDetail();
        this.getBorrowRemark();
        this.getRemarkTable();
        this.getFMTable();
        this.table_borrow_period();
        this.table_borrow_data();
    },
    methods:{
        getBorrowDetail:function(){
            var vm=this;
            vm.$http.post(vm.url,vm.ajax_borrow_array).then(function(res){
                vm.borrow_json=res.data;
                if(vm.borrow_json.borrow_busid=='135') {
                    vm.borrow_json.delay_money =vm.borrow_json.delay_time*vm.borrow_json.borrow_money*10.4/1200;
                }else{
                    vm.borrow_json.delay_money =vm.borrow_json.delay_time*vm.borrow_json.borrow_money*vm.borrow_json.borrow_rate/1200;
                }
                vm.getNewFileCount();
                vm.getCustCredit();
            },function(){
                alert('分期详情请求失败处理');   //失败处理
            });
        },
        getBorrowRemark:function(){
            var vm=this;
            vm.$http.post(vm.remark_url,vm.ajax_borrow_array).then(function(res){
                vm.suppledetail_json=res.data;
                //console.log(vm.suppledetail_json);
            },function(){
                alert('分期备注请求失败处理');   //失败处理
            }); 
        },
        getNewFileCount:function(){
            var vm=this;
            vm.$http.post(vm.newfile_url,{cust_id:vm.borrow_json.borrow_custid}).then(function(res){
                vm.file_count=res.data;
            },function(){
                alert('客户审核材料请求失败处理');   //失败处理
            });
        },
        getCustCredit:function(){
            var vm=this;
            vm.$http.post(vm.credit_url,{cust_id:vm.borrow_json.borrow_custid}).then(function(res){
                vm.zmxy_array1=res.data.zmxy_array1;
                vm.zmxy_array2=res.data.zmxy_array2;
                vm.shzx_array=res.data.shzx_array;
                vm.getZXMYTable();
            },function(){
                alert('客户信用得分请求失败处理');   //失败处理
            });
        },
        getRemarkTable:function(){
            var vm=this;
            vm.$http.post(vm.remark_table_url,vm.ajax_borrow_array).then(function(res){
                var array = $.parseJSON(res.data);
                $('#remark_table').datagrid({loadFilter:pagerFilter}).datagrid('loadData', array);
            },function(){
                alert('分期订单备注请求失败处理');   //失败处理
            });
        },
        getFMTable:function(){
            var vm=this;
            vm.$http.post(vm.fm_table_url,vm.ajax_borrow_array).then(function(res){
                var array = $.parseJSON(res.data);
                $('#FM_table').datagrid({loadFilter:pagerFilter}).datagrid('loadData', array);
            },function(){
                alert('同盾列表请求失败处理');   //失败处理
            });
        },
        getZXMYTable:function(){
            var vm=this;
            if(vm.zmxy_array1.count!=0) {
                vm.$http.post(vm.zmxy_table_url,{cust_id:vm.borrow_json.borrow_custid,num:vm.zmxy_array1.zmscore_num}).then(function (res) {
                    var array = $.parseJSON(res.data);
                    $('#ZMXY_table1').datagrid({loadFilter: pagerFilter}).datagrid('loadData', array);
                }, function () {
                    alert('芝麻信用列表1请求失败处理');   //失败处理
                });
            }
            if(vm.zmxy_array2.count!=0){
                vm.$http.post(vm.zmxy_table_url, {cust_id:vm.borrow_json.borrow_custid,num:vm.zmxy_array2.zmscore_num}).then(function (res) {
                    var array = $.parseJSON(res.data);
                    $('#ZMXY_table2').datagrid({loadFilter: pagerFilter}).datagrid('loadData', array);
                }, function () {
                    alert('芝麻信用列表2请求失败处理');   //失败处理
                });
            }
        },
        goto_cust:function(){
            window.parent.addTab('客户详情','../../customer/customer/customer_see?cust_id='+this.borrow_json.borrow_custid);
        },
        curl_select_zmxy:function(){
            var vm=this;
            vm.$http.post(vm.zmxy_select_url, {cust_id:vm.borrow_json.borrow_custid}).then(function (res) {
                if(res.data.success){
                    alert("操作成功");
                }else{
                    alert("操作失败");
                }
                window.location.reload();
            }, function () {
                alert('芝麻反欺诈查询失败');   //失败处理
            });
        },
        delete_zmxy_score:function(num){
            var vm=this;
            vm.$http.post(vm.zmxy_delete_url, {cust_id:vm.borrow_json.borrow_custid,num:num}).then(function (res) {
                var state=res.data.state;
                var message=res.data.message;
                alert(message);
                window.location.reload();
            }, function () {
                alert('芝麻反欺诈删除请求失败处理');   //失败处理
            });
        },
        select_vpn:function(){
            var vm=this;
            vm.$http.post(vm.vpn_select_url, {cust_id:vm.borrow_json.borrow_custid}).then(function (res) {
                window.location.reload();
            }, function () {
                alert('VPN查询失败');   //失败处理
            });
        },
        look_vpn:function(){
            var vm=this;
            var vpn_annex=vm.shzx_array.vpn_annex;
            window.open(vpn_web_url+vpn_annex);
        },
        down_vpn:function(){
            var vm=this;
            var vpn_annex=vm.shzx_array.vpn_annex;
            window.open(file_down_url+vpn_annex);
        },
        down_load_file:function(){
            var vm=this;
            var contract_annex=vm.borrow_json.contract_annex;
            window.open(contract_web_url+contract_annex);
        },
        first_examine:function(){
            var flag=confirm("是否通过初审");
            if(flag) {
                var vm = this;
                vm.$http.post(vm.anrong_createapply_url, vm.ajax_borrow_array).then(function (res) {
                    var state = res.data.state;
                    var message = res.data.message;
                    alert(message);
                    window.location.reload();
                }, function () {
                    alert('初审操作失败');   //失败处理
                });
            }
        },
        second_examine:function(){
            var flag=confirm("是否通过复审");
            if(flag) {
                var vm = this;
                vm.$http.post(vm.second_examine_url, vm.ajax_borrow_array).then(function (res) {
                    var state = res.data.state;
                    var message = res.data.message;
                    alert(message);
                    window.location.reload();
                }, function () {
                    alert('复审操作失败');   //失败处理
                });
            }
        },
        reject_examine:function(){
            var flag=confirm("是否拒绝该笔订单");
            if(flag) {
                var vm = this;
                vm.$http.post(vm.reject_examine_url, vm.ajax_borrow_array).then(function (res) {
                    var state = res.data.state;
                    var message = res.data.message;
                    alert(message);
                    window.location.reload();
                }, function () {
                    alert('未通过操作失败');   //失败处理
                });
            }
        },
        cancel_borrow:function(){
            var flag=confirm("是否取消该笔订单");
            if(flag) {
                var vm = this;
                vm.$http.post(vm.cancel_borrow_url, vm.ajax_borrow_array).then(function (res) {
                    var state = res.data.state;
                    var message = res.data.message;
                    alert(message);
                    window.location.reload();
                }, function () {
                    alert('取消操作失败');   //失败处理
                });
            }
        },
        file_zip:function(){
            var vm = this;
            vm.$http.post(vm.file_zip_url, {cust_id:vm.borrow_json.borrow_custid}).then(function (res) {
                var state = res.data.state;
                var message = res.data.message;
                alert(message);
                if(state==1) {
                    window.open(file_zip_web_url+vm.borrow_json.borrow_custid+".zip");
                }
            }, function () {
                alert('压缩下载操作失败');   //失败处理
            });
        },
        add_borrow_remark:function(){
            window.parent.addTab('分期备注新增','../../remark/borrowremark/add_borrow_remark?borrow_id='+borrow_id);
        },
        update_borrow_remark:function(remark_id){
            window.parent.addTab('分期备注修改','../../remark/borrowremark/update_borrow_remark?remark_id='+remark_id);
        },
        table_borrow_period:function(){
            var vm = this;
            vm.$http.post(vm.select_borrow_period, vm.ajax_borrow_array).then(function (res) {
                vm.period_array=res.data;
            }, function () {
                alert('请求分期期限失败');   //失败处理
            });
        },
        table_borrow_data:function(){
            var vm = this;
            vm.$http.post(vm.select_borrow_data, vm.ajax_borrow_array).then(function (res) {
                //console.log(res.data);
                vm.data_array=res.data;
            }, function () {
                alert('请求审核资料数据失败');   //失败处理
            });
        },
        submit_period:function(){
            var vm = this;
            if(vm.period_check==null||vm.period_check==''){
                alert("请选择分期期限");
                return ;
            }
            if(vm.period_check.state==1){
                alert("请不要重复提交分期期限");
                return ;
            }
            vm.period_check.borrow_id=vm.ajax_borrow_array.borrow_id;
            vm.$http.post(vm.subimit_borrow_period, vm.period_check).then(function (res) {
                var message=res.data.message;
                alert(message);
                window.location.reload();
            }, function () {
                alert('确认期限操作失败 ');   //失败处理
            });
        },
        submit_data:function(){
            var vm = this;
            var array={data:vm.data_array,borrow_id:vm.ajax_borrow_array.borrow_id,cust_id:vm.borrow_json.borrow_custid}
            vm.$http.post(vm.submit_borrow_data, array).then(function (res) {
                var message=res.data.message;
                alert(message);
                window.location.reload();
            }, function () {
                alert('请求审核资料数据失败');   //失败处理
            });
        }
    }
})

function formatAction(value,row,index)
{
    var c = '<input type="button" value="修改" class="btn" onclick="update_borrow_remark('+row.id+');">';
    return c;
}
function update_borrow_remark(remark_id){
    window.parent.addTab('分期备注修改','../../remark/borrowremark/update_borrow_remark?remark_id='+remark_id);
}